package com.http;

import org.json.JSONArray;

import android.os.AsyncTask;

import com.android.ocean.util.net.ErrorCode;
import com.android.ocean.util.net.NetConUtil;
import com.android.ocean.util.net.ResEntity;
import com.common.method.CommonData;
import com.common.method.ServerPath;
import com.modle.JobStruct;
import com.util.JsonUtil;

/**
 * 
 * @ClassName:JobDetTask
 * @Description:TODO招聘详情
 * @author zhuw
 * @date 2013-8-24 下午11:16:47
 */
public class JobDetTask extends AsyncTask<String, Void, ResultJobStruct> {
	
	public static interface CallBack extends NetWorkCallBack {
		public abstract void procJobDet(JobStruct data);

	}

	CallBack callback;

	public JobDetTask(CallBack callback) {
		super();
		this.callback = callback;
	}

	@Override
	protected ResultJobStruct doInBackground(String... params) {
		ResultJobStruct data = null;
		try {
			ResEntity re=NetConUtil.sendGetRequestEntity(ServerPath.JOB_DET_PATH+params[0]);	
			if(re.code==ResEntity.S_OK){
			    data= new ResultJobStruct(CommonData.H_FLAG_SUCCESS, null, JsonUtil.parseJobStruct(new JSONArray(re.jsonStr).getJSONObject(0)));
			}else if(re.code==ResEntity.S_FAILED){
				
				  data= new ResultJobStruct(CommonData.H_FLAG_ERROR, "code:"+re.code+"    "+re.jsonStr, null);
				
			}else{
				  data= new ResultJobStruct(CommonData.H_FLAG_ERROR, "code:"+re.code+ErrorCode.ERROR_MSG, null);
			}
		} catch (Exception e) {
			data= new ResultJobStruct(CommonData.H_FLAG_ERROR, ErrorCode.ERROR_MSG, null);
			e.printStackTrace();

		}
		return data;
	}

	@Override
	protected void onPostExecute(ResultJobStruct result) {
		if (result.flag == CommonData.H_FLAG_SUCCESS) {
			callback.procJobDet(result.data);

		} else {
			callback.procError(result.msg);
		}

	}
}
